<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="h" uri="http://cn.gson.com/jsp/mytag" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>诊疗卡管理界面</title>
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/zhenliaoka.css">
<link rel="stylesheet" href="static/easyui/themes/ui-cupertino/easyui.css">
</head>
<body>
<script type="text/javascript"> 
$(function(){
	$.extend($.fn.validatebox.defaults.rules, {
   	 brage:{
             validator: function(value, param){
               //自定义正则验证,密码验证
               var reg = /^[1-9]\d*$/;
               return reg.test(value);
             },
             message:'年龄格式错误'
       },
   });
	 
   $.extend($.fn.validatebox.defaults.rules, {
   	 brname:{
             validator: function(value, param){
               //自定义正则验证,密码验证
               var reg = /^([a-zA-Z0-9\u4e00-\u9fa5\·]{1,10})$/;
               return reg.test(value);
             },
             message:'姓名格式错误'
       },
   });
   
   $.extend($.fn.validatebox.defaults.rules, {
   	 brsfz:{
             validator: function(value, param){
               //自定义正则验证,密码验证
               var reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
               return reg.test(value);
             },
             message:'身份证号格式错误'
       },
   });
   
   $.extend($.fn.validatebox.defaults.rules, {
   	 brdh:{
             validator: function(value, param){
               //自定义正则验证,密码验证
               var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
               return reg.test(value);
             },
             message:'电话号码格式错误'
       },
   });
   
   $.extend($.fn.validatebox.defaults.rules, {
   	 brdz:{
             validator: function(value, param){
               //自定义正则验证,密码验证
               var reg = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;
               return reg.test(value);
             },
             message:'家庭住址格式错误'
       },
   });
});
//时间转换
function comformatDate(date) {
	var day = new Date(date); 
	var Year = 0; 
	var Month = 0; 
	var Day = 0; 
	var CurrentDate = ""; 
	//初始化时间 
	Year= day.getFullYear();//
	Month= day.getMonth()+1; 
	Day = day.getDate(); 
	Hour = day.getHours(); 
	 Minute = day.getMinutes(); 
	 Second = day.getSeconds(); 
	CurrentDate += Year + "-"; 
	if (Month >= 10 ) { 
		CurrentDate += Month + "-"; 
	}else { 
		CurrentDate += "0" + Month + "-"; 
	} 
	if (Day >= 10 ) { 
		CurrentDate += Day ; 
	}else { 
		CurrentDate += "0" + Day ; 
	} 
	if(Hour>=10){
		CurrentDate +=" "+Hour;
	}else{
		CurrentDate +=" "+"0"+Hour;
	}
	if(Minute>=10){
		CurrentDate +=":"+Minute;
	}else{
		CurrentDate +=":"+"0"+Minute;
	}
	if(Second>=10){
		CurrentDate +=":"+Second;
	}else{
		CurrentDate +=":"+"0"+Second;
	}
	return CurrentDate; 
};

	$(function(){
		/* 挂失弹出层 */
		$("#gua").click(function(){
			   $("#gua_shi").window("open");
			   $("#bu_patient").datagrid("reload");

		  });
		//挂失确定按钮点击事件
		 $("#gsqr").click(function(){
			var medid=$("#gua_patient").datagrid("getSelected");
			if(medid==null){
				$.messager.alert("温馨提示：","对不起您未选中表格信息");
			}else{
				if(medid!=null){
					var iddd=medid.mzcard_id;
					$.ajax({
						url:'xiugaika',
						type:'post',
						data:{
							"mzcardId":iddd
						},
						success:function(d){
							if(parseInt(d)==1){
								$("#gua_patient").datagrid("reload");
								$("#zlk1_table").datagrid("reload");
								$.messager.show({
									title:'提 示',
									msg:'医疗卡挂失成功！！！！！！！',
									height:200,
									timeout:1000,
									showType:'slide'
								 });
					 		}else{
					 			$.messager.alert("温馨提示：","医疗卡挂失失败！");
					 		}
						}
					})	
				}else{
					$("#gswxz").window("open");
				}
			}
		});
		//挂失未选中提示框关闭事件
		$("#gswxzqr").click(function(){
			$("#gswxz").window("close");
		});
		/* 补办弹出表格=============================== */
		$("#bu").click(function(){
			   $("#bu_ban").window("open");
			   $("#gua_patient").datagrid("reload");
		 });
		//补办表格点击事件用来得到选中行的id主键
		$('#bu_patient').datagrid({
			onSelect:function(){
		    	var row=$("#bu_patient").datagrid("getSelected");
		    	//存进隐藏域
		    	$("#buid").val(row.mzcard_id);
		    	//得到医疗卡号做展示用
		    	$("#mednuber").val(row.mecard_number);
		    }
		});
		//补办确认按钮点击事件获得存进隐藏域的id值
		$("#buqr").click(function(){
			var row=$("#bu_patient").datagrid("getSelected");
			if(row==''){
				$.messager.alert("温馨提示：","对不起您未选中表格信息");
			}else{
				var yid=$('#buid').val();
				if(yid!=''){
					$.ajax({
						url:'buban',
						type:'post',
						data:{
							"mzcardId":yid,
						},
						success:function(d){
							if(parseInt(d)!=0){
								 $("#bu_patient").datagrid("reload");
								 $("#zlk2_table").datagrid("reload");
								 //原医疗卡号和新医疗卡号展示
								 $("#yuanyiliaoka").textbox("setValue",$('#mednuber').val());
								 $("#xinyiliaoka").textbox("setValue",d);
								 $("#buid").val(null);
								 $("#bkwctk").window("open");
					 		}else{
					 			alert("失败!!!!!！！");
					 		}
						}
					});
				}else{
					$.messager.alert("温馨提示：","对不起您未选中补办的医疗卡！");
					
				}
			}
		})	
	});
		//办卡记录表格初始化
		$(function(){
			//访问数据源、初始化表格
			$('#zlk_table').datagrid({
			    url:'yiliaok',
				pagination:true,
			    pageNumber:1,
			    pageSize:5,
			    pageList:[5,6],
			    columns:[[
					{field:'mecard_number',title:'医疗卡编号',width:180,align:'center'},
					{field:'patient_name',title:'病人姓名',width:100,align:'center'},
					{field:'patient_age',title:'病人年龄',width:100,align:'center'},
					{field:'patient_sex',title:'病人性别',width:100,align:'center'},
					{field:'card_cid',title:'病人身份证号',width:220,align:'center'},
					{field:'mzcard_phone',title:'联系电话',width:160.2,align:'center'},
					{field:'card_date',title:'办卡时间',width:200,align:'center',formatter:comformatDate},
					{field:'medicalcard_state',title:'状态',width:110.2,align:'center',
						formatter:function(value){
							if(value==1){
								return "已挂失";
							}
							return "正常";
						}}
			    ]],   
			});	
		});
		//挂失记录
		$(function(){
			//访问数据源、初始化表格
			$('#zlk1_table').datagrid({
			    url:'guashi',
				pagination:true,
			    pageNumber:1,
			    pageSize:5,
			    pageList:[5,6],
			    columns:[[
					{field:'mecard_number',title:'医疗卡编号',width:200,align:'center'},
					{field:'patient_name',title:'病人姓名',width:100,align:'center'},
					{field:'patient_age',title:'病人年龄',width:100,align:'center'},
					{field:'patient_sex',title:'病人性别',width:100,align:'center'},
					{field:'card_cid',title:'病人身份证号',width:220,align:'center'},
					{field:'mzcard_phone',title:'联系电话',width:160.2,align:'center'},
					{field:'loss_date',title:'挂失时间',width:200,align:'center',formatter:comformatDate},
					{field:'gsblr',title:'办理人',width:180,align:'center'},
			    ]]
			});
		});
		
		//补办记录
		$(function(){
			//访问数据源、初始化表格
			$('#zlk2_table').datagrid({
			    url:'findreplace',
			    pagination:true,
			    pageNumber:1,
			    pageSize:5,
			    pageList:[5,6],
			    columns:[[
			    	{field:'mumber',title:'原医疗卡编号',width:180,align:'center'},
					{field:'mecard_number',title:'新医疗卡编号',width:180,align:'center'},
					{field:'patient_name',title:'病人姓名',width:100,align:'center'},
					{field:'patient_age',title:'病人年龄',width:70,align:'center'},
					{field:'patient_sex',title:'病人性别',width:70,align:'center'},
					{field:'card_cid',title:'病人身份证号',width:180,align:'center'},
					{field:'mzcard_phone',title:'联系电话',width:125.2,align:'center'},
					{field:'replacedate',title:'补办时间',width:170,align:'center',formatter:comformatDate},
					{field:'replace_name',title:'办理人',width:80,align:'center'},
			    ]]
			});
		});
		//=================医疗卡新增
		$(function(){
			$("#bc").click(function(){
				//姓名
				var xm=$('#name_').val();
				//年龄
				var age=$('#age').val();
				//性别
				var sex=$('#sex option:selected').text();
				//身份证号
				var sfz=$('#sfz').val();
				//联系电话
				var dh=$('#dianhua').val();
				//现居地址
				var dizhi=$('#dizhi').val();
				if(xm==''){
					 $.messager.confirm('温馨提示','姓名输入不能为空',{	
						});
					 return;
				}else if(age==''){
					$.messager.confirm('温馨提示','年龄输入不能为空',{	
					});
				}else if(sfz==''){
					$.messager.confirm('温馨提示','身份证输入不能为空',{	
					});
				}else if(dh==''){
					$.messager.confirm('温馨提示','电话输入不能为空',{
						
					});
				}else{
					$.ajax({
						 url:'medicl',
						type:'post',
						data:{
							 "patientName":xm,
							 "patientAge":age,
							 "patientSex":sex,
							 "cardCid":sfz,
							 "mzcardPhone":dh,
							 "homeAddress":dizhi
							
						},
						success:function(d){
							if(parseInt(d)==1){
					 			//姓名
								$("#name_").textbox("setValue",null); 
								//年龄
								$("#age").textbox("setValue",null); 
								//身份证号
								$("#sfz").textbox("setValue",null); 
								//联系电话
								$("#dianhua").textbox("setValue",null);
								//现居地址
								$("#dizhi").textbox("setValue",null); 
					 			 $("#zlk_table").datagrid("reload");
					 			$.messager.show({
									title:'提 示',
									msg:'医疗卡办理成功！！！！！！！',
									height:200,
									timeout:2000,
									showType:'slide'
								 });
					 		}else if(parseInt(d)==2){
					 			$.messager.alert("温馨提示：","！！！对不起已存在改用户,请重新输信息");
					 		}else{
					 			$.messager.alert("温馨提示：","医疗卡办理失败！");
					 		}
						}
					});
				}	
			});
			//医疗卡办理取消事件
			$("#quxiao").click(function(){
				//姓名
				$("#name_").textbox("setValue",null); 
				//年龄
				$("#age").textbox("setValue",null); 
				//身份证号
				$("#sfz").textbox("setValue",null); 
				//联系电话
				$("#dianhua").textbox("setValue",null);
				//现居地址
				$("#dizhi").textbox("setValue",null); 
			});
			
		});
		
$(function(){
	//根据医疗卡号查询用户办卡记录
	$('#card').searchbox({
		searcher:function(value,name){
		    $('#zlk_table').datagrid({
		    	  url:'findid?mecard_number='+value
				});
		   $("#card").textbox("setValue",null); 
		  } 
	});
	//根据医疗卡号查询用户挂失记录
	$('#card2').searchbox({
		searcher:function(value,name){
		    $('#zlk1_table').datagrid({
		    	url:'cardghjl?mecard_number='+value
				});
		   $("#card2").textbox("setValue",null); 
		  } 
	});
	//根据医疗卡号查询用户补办记录
	$('#card3').searchbox({
		searcher:function(value,name){
		    $('#zlk2_table').datagrid({
		    	url:'bbjl?mecard_number='+value
				});
		   $("#card3").textbox("setValue",null); 
		  } 
	});
	//医疗卡挂失里面根据医疗卡号查询医疗卡信息
	$('#gscard').searchbox({
		searcher:function(value,name){
		    $('#gua_patient').datagrid({
		    	 url:'idmedical?mecard_number='+value
				});
				$("#gscard").textbox("setValue",null);
		  
		  } 
	});
	//医疗卡挂失里面根据身份证卡号查询医疗卡信息
	$('#gssfz').searchbox({
		searcher:function(value,name){
		    $('#gua_patient').datagrid({
		    	 url:'sfzcx?card_cid='+value
				});
		    $("#gssfz").textbox("setValue",null); 
		  
		  } 
	});
	//医疗卡补办根据医疗卡查询
	$('#bucard').searchbox({
		searcher:function(value,name){
		    $('#bu_patient').datagrid({
		    	url:'findid?mecard_number='+value
				});
		    $("#bucard").textbox("setValue",null); 
		  
		  } 
	});
	//医疗卡补办根据身份证查询
	$('#busfz').searchbox({
		searcher:function(value,name){
		    $('#bu_patient').datagrid({
		    	url:'sfzsy?card_cid='+value
				});
		    $("#busfz").textbox("setValue",null); 
		  } 
	});
	//关闭补办弹框事件
	$("#bbwzqr").click(function(){
		$("#bkwctk").window("close");
	});
	
});

</script>
	<!-- =============改面板最大盒子===========  -->
	<div class="easyui-layout" data-options="region:'west',title:'诊疗',split:true,collapsible:false"style="width:600;border:none">
			<!-- =============上面信息输入盒子===========  -->
		<div class="shang" style="float:left;border:1px solid #19AA8D;margin:10px;width:986px;border-radius:5px;">
			<form action="ylk" id="cw_added" method="post">
					<p>
						<span style="margin-left:10px;">
							<input name="Name_" id="name_"  class="easyui-textbox"  required="required"
									data-options="label:'病人姓名：',validType:'brname',width:270,labelAlign:'right'">
						</span>
						
						<span style="margin-left:20px;">
							<input name="Age_"  id="age" class="easyui-textbox"  required="required"
							data-options="label:'病人年龄：',width:270,validType:'brage',labelAlign:'right'">
						</span>
				
						<span style="margin-left:20px;">
							<select id="sex" class="easyui-combobox"  panelHeight='auto';
							data-options="label:'性别：',width:270,labelAlign:'right'">   
   									 <option value="男" selected="selected">男</option>   
    								 <option value="女">女</option>   
							</select>  
							
						</span>
					</p>		
					<p>
						<span style="margin-left:10px;">
							<input name="Sf_" id="sfz" class="easyui-textbox"  required="required"
									data-options="label:'身份证号：',validType:'brsfz',width:270,labelAlign:'right'">
						</span>
						<span style="margin-left:20px;">
							<input name="Dain_" id="dianhua" class="easyui-textbox"  required="required"
									data-options="label:'联系电话：',validType:'brdh',width:270,labelAlign:'right'">
						</span>
					</p>
					<p>
						<span style="margin-left:10px;">
							<input name="Diz_" id="dizhi" class="easyui-textbox"  required="required"
									data-options="label:'现居地址：',validType:'brdz',width:470,labelAlign:'right'">
						</span>
					</p>
			<!-- 	=============两个按钮=========== --> 
			<a class='easyui-linkbutton que' style="margin-left:770px;height:30px;margin-bottom:10px;"id="bc">确认</a>		
			<a class='easyui-linkbutton qu' style="margin-left:5px;margin-bottom:10px;height:30px;"id="quxiao">取消</a>
			</form> 
		</div>
		
		<div class="easyui-layout" style="border:1px solid #19AA8D;width:114px;height:186px;float:right;border-radius:5px;margin-right:14px;margin-left:-5px;margin-top:10px;" >
				<div style="margin-top:30px;"><a class='easyui-linkbutton' id="gua"style="margin-left:13px;">医疗卡挂失</a></div>
				<div style="margin-top:40px;"><a class='easyui-linkbutton' id="bu"style="margin-left:13px;">医疗卡补办</a></div>
		</div>
		<div style="clear:both;"></div>
		 		<div class="easyui-tabs" style="margin-top:10px;">
				<div title="办卡记录">
				
							<div class="easyui-layout" style="border:1px solid #19AA8D;margin:5px;background:white">
						
							<div class="didd_1" style="margin-top:5px;margin-bottom:5px;">
								<span>
								
									<input id="card" class="easyui-searchbox" style="width:260px;height:30px;"
									data-options="label:'记录检索：',prompt:'医疗卡号',labelAlign:'right'">
								</span>
							</div>
							
							<!-- 底部表格 -->
							<table id="zlk_table" style="height:250px;width:1130px;" class="easyui-datagrid" data-options="fitColumns:true">
						 			
							</table>
						</div> 
				</div>
				<div title="挂失记录">
						<div class="easyui-layout" style="border:1px solid #19AA8D;margin:5px;background:white">
						
							<div class="guahaijilu" style="margin-top:5px;margin-bottom:5px;">
								<span>
									<input id="card2" class="easyui-searchbox" style="width:260px;height:30px;"
									data-options="label:'记录检索：',prompt:'医疗卡号',labelAlign:'right'">
								</span>
							</div>
							
							<!-- 底部表格 -->
							<table id="zlk1_table" style="height:250px;width:1130px;" class="easyui-datagrid" data-options="fitColumns:true">
						 			
							</table>
						</div> 
				</div>
				<div title="补办记录">
						<div class="easyui-layout" style="border:1px solid #19AA8D;margin:5px;background:white">
						
							<div class="bankajilu" style="margin-top:5px;margin-bottom:5px;">
								<span>
									<input id="card3" class="easyui-searchbox" style="width:260px;height:30px;"
									data-options="label:'记录检索：',prompt:'医疗卡号',labelAlign:'right'">
								</span>
							</div>
						<!-- 底部表格 -->
							<table id="zlk2_table" style="height:250px;width:1130px;" class="easyui-datagrid" data-options="fitColumns:true">
						 			
							</table>
						</div> 
				</div>
		</div> 
	</div>
		<!-- 医疗卡挂失 -->
		<div id="gua_shi" class="easyui-window" title="医疗卡挂失" style="width:750 px;"
				data-options="iconCls:'',modal:true,closed:true">
			
			<div class="easyui-layout" style="width:735px;;height:50px;background-color:#C8F7F7;padding:16px;">
				<a id="gsqr" href="#" class="easyui-linkbutton"
						data-options="iconCls:'icon-add',plain:true" style="width: 80px,background-color:#D6FEFD;">确认</a>
						
				<input name="Yi_Id1" id="gscard" class="easyui-searchbox"
				data-options="label:'医疗卡号：',prompt:'请输入医疗卡号',width:240,labelAlign:'right'">
				
				<input name="User_Id1" id="gssfz" class="easyui-searchbox"
				data-options="label:'身份证号：',prompt:'请输入身份证号',width:260,labelAlign:'right'">
			</div>
			<div class="easyui-layout" style="height:390px;width:735px;">
				<table  id="gua_patient" class="easyui-datagrid" singleSelect="true" style="height:390px;"
						url="zcyiliaok"
			    	data-options="pagination:true,pageNumber:1,pageSize:10,pageList:[10]">
			   		 <thead>
						<tr id="">
							<th hidden="true"  data-options="field:'mzcard_id',width:160,align:'center'">编号</th>
							<th data-options="field:'mecard_number',width:160,align:'center'">医疗卡编号</th>
							<th data-options="field:'patient_name',width:86,align:'center'">病人姓名</th>
							<th data-options="field:'patient_age',width:86,align:'center'">病人年龄</th>
							<th data-options="field:'patient_sex',width:86,align:'center'">病人性别</th>
							<th data-options="field:'card_cid',width:180,align:'center'">病人身份证号</th>
							<th data-options="field:'mzcard_phone',width:125,align:'center'">联系电话</th>
						</tr>
				    </thead>				
				</table>
		</div>
		</div>
		<!--  医疗卡补办 -->
		<div id="bu_ban" class="easyui-window" title="医疗卡补办" style="width:750px;"
				data-options="iconCls:'',modal:true,closed:true">
			
			<div  class="easyui-layout" style="width:735px;height:50px;background-color:#C8F7F7;padding:16px;">
				<a id="buqr" href="#" class="easyui-linkbutton"
						data-options="iconCls:'icon-add',plain:true" style="width: 80px,background-color:#D6FEFD;">确认</a>		
				<input name="Yi_Id2" id="bucard" class="easyui-searchbox"
				data-options="label:'医疗卡号：',prompt:'请输入医疗卡号',width:240,labelAlign:'right'">	
				<input name="User_Id2" id="busfz" class="easyui-searchbox"
				data-options="label:'身份证号：',prompt:'请输入身份证号',width:260,labelAlign:'right'">
	
				<!-- ====================医疗卡补办id隐藏域===================== -->
				<input type="hidden" type="text" id="buid" >
				<input type="hidden" type="text" id="mednuber" >
			</div>
			<div class="easyui-layout" style="height:410px;width:735px;">
				<table  id="bu_patient" class="easyui-datagrid" singleSelect="true" style="height:410px;"
					url="yiliaok"
			    	data-options="pagination:true,pageNumber:1,pageSize:10,pageList:[10]">
			   		 <thead>
						<tr>
							<th hidden="true" data-options="field:'mzcard_id',width:160,align:'center'">编号</th>
							<th data-options="field:'mecard_number',fixed:false,resiable:true,width:160,align:'center'">医疗卡编号</th>
							<th data-options="field:'patient_name',fixed:false,resiable:true,width:86,align:'center'">病人姓名</th>
							<th data-options="field:'patient_age',fixed:false,resiable:true,width:86,align:'center'">病人年龄</th>
							<th data-options="field:'patient_sex',fixed:false,resiable:true,width:86,align:'center'">病人性别</th>
							<th data-options="field:'card_cid',fixed:false,resiable:true,width:180,align:'center'">病人身份证号</th>
							<th data-options="field:'mzcard_phone',fixed:false,resiable:true,width:125,align:'center'">联系电话</th>
						</tr>
						
				    </thead>
				   
				</table>
		</div>
		</div>
		<!-- 挂失未选中-->
		<div id="gswxz" class="easyui-window" title="温馨提示" style="width:300px;height:170px;"
				data-options="iconCls:'',modal:true,closed:true">
				
					<div style="margin:15px;margin-left:100px;font-size:16px;">对不起您未选中行！！！！</div>
				<div>
					<input type="button" id="gswxzqr"style="margin-left:110px;background:#C8F7F7;color:#2779AA;border:none;height:30px;width:50px;"value="确认"/>
				</div>
		</div>
		
		
		<!--补办弹框-->
		<div id="bkwctk" class="easyui-window" title="温馨提示" style="width:300px;height:185px;"
				data-options="iconCls:'',modal:true,closed:true">
					<p style="padding-left:40px;">原卡号:&nbsp;&nbsp;<input id="yuanyiliaoka" class="easyui-textbox"  required="required"
								data-options="label:'',width:160,labelAlign:'right',disabled:true"> </p>
					<p style="padding-left:40px;">新卡号:&nbsp;&nbsp;<input  id="xinyiliaoka" class="easyui-textbox"  required="required"
								data-options="label:'',width:160,labelAlign:'right',disabled:true"> </p>
				<div>
						<a class='easyui-linkbutton' style="margin-left:120px;height:30px;margin-bottom:10px;"id="bbwzqr">确认</a>		
				</div>
		</div>
</body>
</html>